package com.gukewen.aihaiguitang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gukewen.aihaiguitang.entity.Conversation;
import com.gukewen.aihaiguitang.entity.dto.PageDTO;
import com.gukewen.aihaiguitang.entity.dto.SendDTO;
import com.gukewen.aihaiguitang.entity.vo.StartVO;
import com.gukewen.aihaiguitang.service.ChatService;
import com.gukewen.aihaiguitang.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private ChatService chatService;

    /**
     * 开始游戏
     * @return
     */
    @GetMapping("/start")
    public Result start() {
        StartVO startVO = chatService.start();
        return Result.success(startVO);
    }


    @PostMapping("/send")
    public Result send(@RequestBody  SendDTO sendDTO) {
        return chatService.send(sendDTO.getRoomId(), sendDTO.getMessage());
    }

    /**
     * 获取房间列表
     * @return
     */
    @GetMapping("/list")
    public  Result list(PageDTO pageDTO) {
        IPage<Conversation> page = chatService.getRoomPage(pageDTO);
        return Result.success(page);
    }

    @GetMapping("/detail")
    public Result detail(Long roomId) {
        return chatService.getDetail(roomId);
    }


}
